import  CryptoTs from "crypto-ts";

export class GameCrypto {
    public static md5(origin: string) {
        console.log(CryptoTs);
        // var hash = CryptoTs.AES.encrypt(origin, Constants.ENCRYPT_KEY).toString();
        var hash = CryptoTs.MD5(origin);
        console.log("md5: "+hash)
        return hash;
    }

    public static aesDecrypt(text: string, key: string) {
        var bytes = CryptoTs.AES.decrypt(text, CryptoTs.enc.Utf8.parse(key), {
            mode:CryptoTs.mode.ECB,
            padding:CryptoTs.pad.PKCS7
        });
        var plaintext = bytes.toString(CryptoTs.enc.Utf8);
        // console.log("test plaintext:"+plaintext);
        return plaintext;
    }

    public static aesEncrypt(text: string, key: string) {
        var test = "token=f58777c4725dbb68cf5437c06737c5d4&gameid=0";
        var ciphertext = CryptoTs.AES.encrypt(test, CryptoTs.enc.Utf8.parse(key), {
            mode:CryptoTs.mode.ECB,
            padding:CryptoTs.pad.PKCS7
        });
        // console.log("test chiper:"+ciphertext);
        return ciphertext;
    }
}

